#!/usr/bin/env python

import sys
import os
from PyQt4 import QtCore, QtGui

try :
    import maya.cmds as cmds
    import maya.mel as mel
    MAYA = 1
except :
    MAYA = 0

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s
    
    
class crowd_ui( QtGui.QMainWindow ) :
    def __init__( self , parent = None ) :
        QtGui.QMainWindow.__init__( self , parent )
        
    def setupUi(self):
        self.setWindowTitle( 'Moneagi' )
        font = QtGui.QFont()
        font.setPointSize(11)        
        
        self.resize(433, 315)
        self.tabWidget = QtGui.QTabWidget( self )
        self.tabWidget.setGeometry(QtCore.QRect( 10, 10, 411, 300 ) )
        
        self.tab_1 = QtGui.QWidget()
        self.tabWidget.addTab( self.tab_1 , 'Ground' )
        
        self.tab1_lineEdit = QtGui.QLineEdit(self.tab_1)
        self.tab1_lineEdit.setGeometry(QtCore.QRect(10, 10, 361, 20))
        self.tab1_lineEdit.setText( 'ground' )
        
        self.tab1_width_lb = QtGui.QLabel(self.tab_1)
        self.tab1_width_lb.setGeometry(QtCore.QRect(20, 40, 41, 21))
        self.tab1_width_lb.setText('Width')
        self.tab1_width_lb.setFont(font)
        
        self.tab1_width_spin = QtGui.QSpinBox(self.tab_1)
        self.tab1_width_spin.setGeometry(QtCore.QRect(100, 40, 61, 22))
        self.tab1_width_spin.setMaximum(100000)
        self.tab1_width_spin.setValue(1000)
        
        self.tab1_height_lb = QtGui.QLabel(self.tab_1)
        self.tab1_height_lb.setGeometry(QtCore.QRect(20, 70, 51, 21))
        self.tab1_height_lb.setText( 'Height' )
        self.tab1_height_lb.setFont(font)

        self.tab1_height_spin = QtGui.QSpinBox(self.tab_1)
        self.tab1_height_spin.setGeometry(QtCore.QRect(100, 70, 61, 22))
        self.tab1_height_spin.setMaximum(100000)
        self.tab1_height_spin.setValue( 1000 )

        self.tab1_subWidth_lb = QtGui.QLabel(self.tab_1)
        self.tab1_subWidth_lb.setGeometry(QtCore.QRect(190, 40, 111, 21))
        self.tab1_subWidth_lb.setText( 'subdivisionWidth' )
        self.tab1_subWidth_lb.setFont( font )
        
        self.tab1_subWidth_spin = QtGui.QSpinBox(self.tab_1)
        self.tab1_subWidth_spin.setGeometry(QtCore.QRect(310, 40, 61, 22))        
        self.tab1_subWidth_spin.setValue(10)       

        self.tab1_subHeight_lb = QtGui.QLabel(self.tab_1)
        self.tab1_subHeight_lb.setGeometry(QtCore.QRect(190, 70, 111, 21))
        self.tab1_subHeight_lb.setText( 'subdivisionHeight')
        self.tab1_subHeight_lb.setFont( font )
        
        self.tab1_subHeight_spin = QtGui.QSpinBox(self.tab_1)
        self.tab1_subHeight_spin.setGeometry(QtCore.QRect(310, 70, 61, 22))
        
        self.tab1_subHeight_spin.setValue( 10 )
        
        self.tab1_crtGrd_btn = QtGui.QPushButton(self.tab_1)
        self.tab1_crtGrd_btn.setGeometry(QtCore.QRect(10, 100, 361, 31))
        self.tab1_crtGrd_btn.setText( 'Create Ground' )
        self.tab1_crtGrd_btn.setFont( font )
        
        self.tab1_noisePick_lb = QtGui.QLabel(self.tab_1)
        self.tab1_noisePick_lb.setGeometry(QtCore.QRect(20, 150, 71, 21))
        self.tab1_noisePick_lb.setText( 'noisePick' )
        self.tab1_noisePick_lb.setFont(font)
        
        self.tab1_noisePick_spin = QtGui.QSpinBox(self.tab_1)
        self.tab1_noisePick_spin.setGeometry(QtCore.QRect(100, 150, 61, 22))
        self.tab1_noisePick_spin.setValue( 5 )
        
        self.tab1_noiseStrength_lb = QtGui.QLabel( self.tab_1  )        
        self.tab1_noiseStrength_lb.setGeometry(QtCore.QRect(190, 150, 111, 21))
        self.tab1_noiseStrength_lb.setText('NoiseStrength')
        self.tab1_noiseStrength_lb.setFont(font)        
               
        self.tab1_noiseStrength_spin = QtGui.QSpinBox(self.tab_1)
        self.tab1_noiseStrength_spin.setGeometry(QtCore.QRect(310, 150, 61, 22))
        self.tab1_noiseStrength_spin.setMaximum(100000)
        self.tab1_noiseStrength_spin.setValue( 50 )

        self.tab1_noiseScale_lb = QtGui.QLabel(self.tab_1)
        self.tab1_noiseScale_lb.setGeometry(QtCore.QRect(20, 180, 71, 21))
        self.tab1_noiseScale_lb.setText( 'noiseScale' )
        self.tab1_noiseScale_lb.setFont(font)
        
        self.tab1_noiseScale_spin = QtGui.QSpinBox(self.tab_1)
        self.tab1_noiseScale_spin.setGeometry(QtCore.QRect(100, 180, 61, 22))
        self.tab1_noiseScale_spin.setMaximum(100000)
        self.tab1_noiseScale_spin.setValue(200)       
        
        self.tab1_noise_btn = QtGui.QPushButton(self.tab_1)
        self.tab1_noise_btn.setGeometry(QtCore.QRect(10, 210, 361, 31))
        self.tab1_noise_btn.setText( 'Noise' )
        self.tab1_noise_btn.setFont(font)
        self.tab1_noise_btn.setEnabled( False )
        
        #self.tab1_resetNoise_btn = QtGui.QPushButton(self.tab_1)
        #self.tab1_resetNoise_btn.setGeometry(QtCore.QRect(20, 210, 161, 31))
        #self.tab1_resetNoise_btn.setText( 'Reset Noise' )
        #self.tab1_resetNoise_btn.setFont(font)

        self.tab_2 = QtGui.QWidget()
        self.tabWidget.addTab(self.tab_2 , 'Scattering Plane' )
        
        self.tab2_plane_line = QtGui.QLineEdit(self.tab_2)
        self.tab2_plane_line.setGeometry(QtCore.QRect(10, 10, 361, 20))
        self.tab2_plane_line.setText( 'scatter' )
        
        self.tab2_width_lb = QtGui.QLabel(self.tab_2)
        self.tab2_width_lb.setGeometry(QtCore.QRect(20, 40, 41, 21))
        self.tab2_width_lb.setText( 'Width' )
        self.tab2_width_lb.setFont(font)        
        
        self.tab2_width_spin = QtGui.QSpinBox(self.tab_2)
        self.tab2_width_spin.setGeometry(QtCore.QRect(100, 40, 61, 22))
        self.tab2_width_spin.setMaximum(100000)
        self.tab2_width_spin.setValue( 100 )
        
        self.tab2_height_lb = QtGui.QLabel(self.tab_2)
        self.tab2_height_lb.setGeometry(QtCore.QRect(20, 70, 51, 21))
        self.tab2_height_lb.setText( 'Height' )
        self.tab2_height_lb.setFont(font)
        
        self.tab2_height_spin = QtGui.QSpinBox(self.tab_2)
        self.tab2_height_spin.setGeometry(QtCore.QRect(100, 70, 61, 22))
        self.tab2_height_spin.setMaximum(100000)
        self.tab2_height_spin.setValue( 100 )
        
        self.tab2_subWidth_lb = QtGui.QLabel(self.tab_2)
        self.tab2_subWidth_lb.setGeometry(QtCore.QRect(190, 40, 111, 21))
        self.tab2_subWidth_lb.setText( 'subdivisionWidth' )
        self.tab2_subWidth_lb.setFont( font )
        
        self.tab2_subWidth_spin = QtGui.QSpinBox(self.tab_2)
        self.tab2_subWidth_spin.setGeometry(QtCore.QRect(310, 40, 61, 22))
        self.tab2_subWidth_spin.setValue( 10 )
        
        self.tab2_subHeight_lb = QtGui.QLabel(self.tab_2)
        self.tab2_subHeight_lb.setGeometry(QtCore.QRect(190, 70, 111, 21))
        self.tab2_subHeight_lb.setText( 'subdivisionHeight' )
        self.tab2_subHeight_lb.setFont( font )
        
        self.tab2_subHeight_spin = QtGui.QSpinBox(self.tab_2)
        self.tab2_subHeight_spin.setGeometry(QtCore.QRect(310, 70, 61, 22))
        self.tab2_subHeight_spin.setValue( 10 )
        
        self.tab2_crtPlane_btn = QtGui.QPushButton(self.tab_2)
        self.tab2_crtPlane_btn.setGeometry(QtCore.QRect(20, 100, 351, 31))
        self.tab2_crtPlane_btn.setText( 'Create Scatter Plane' )
        self.tab2_crtPlane_btn.setFont( font )
        
        self.tab2_noiseStrength_lb = QtGui.QLabel(self.tab_2)
        self.tab2_noiseStrength_lb.setGeometry(QtCore.QRect(10, 140, 111, 21))
        self.tab2_noiseStrength_lb.setText( 'noiseStrength' )
        self.tab2_noiseStrength_lb.setFont( font )
        
        self.tab2_noiseStrength_spin = QtGui.QSpinBox(self.tab_2)
        self.tab2_noiseStrength_spin.setGeometry(QtCore.QRect(130, 140, 61, 22))        
        self.tab2_noiseStrength_spin.setValue( 2 )
        
        self.tab2_resetNoise_btn = QtGui.QPushButton(self.tab_2)
        self.tab2_resetNoise_btn.setGeometry(QtCore.QRect(20, 170, 161, 31))
        self.tab2_resetNoise_btn.setText( 'Reset Noise' )
        self.tab2_resetNoise_btn.setFont( font )
        
        self.tab2_noise_btn = QtGui.QPushButton(self.tab_2)
        self.tab2_noise_btn.setGeometry(QtCore.QRect(210, 170, 161, 31))
        self.tab2_noise_btn.setText( 'Noise' )
        self.tab2_noise_btn.setFont( font )
        
        self.tab2_attach2GRD_btn = QtGui.QPushButton(self.tab_2)
        self.tab2_attach2GRD_btn.setGeometry(QtCore.QRect(20, 220, 351, 31))
        self.tab2_attach2GRD_btn.setText( 'Attache To Ground' )
        self.tab2_attach2GRD_btn.setFont( font )
        self.tab2_attach2GRD_btn.setEnabled( False )
        
        self.tab_3 = QtGui.QWidget()
        self.tabWidget.addTab(self.tab_3, 'Sources' )
        
        self.tab3_modelList_lb = QtGui.QLabel(self.tab_3)
        self.tab3_modelList_lb.setGeometry(QtCore.QRect(10, 10, 71, 16))
        self.tab3_modelList_lb.setText( '[ Model List ]' )
        
        self.tab3_model_list = QtGui.QListWidget(self.tab_3)
        self.tab3_model_list.setSelectionMode(QtGui.QAbstractItemView.MultiSelection)
        self.tab3_model_list.setGeometry(QtCore.QRect(10, 30, 191, 192))
        
        self.tab3_modelImport_btn = QtGui.QPushButton(self.tab_3)
        self.tab3_modelImport_btn.setGeometry(QtCore.QRect(10, 230, 91, 31))
        self.tab3_modelImport_btn.setText( 'Import' )
        
        self.tab3_modelDelete_btn = QtGui.QPushButton(self.tab_3)
        self.tab3_modelDelete_btn.setGeometry(QtCore.QRect(114, 230, 91, 31))
        self.tab3_modelDelete_btn.setText( 'Delete' )
        
        self.tab3_motionList_lb = QtGui.QLabel(self.tab_3)
        self.tab3_motionList_lb.setGeometry(QtCore.QRect(210, 10, 71, 16))
        self.tab3_motionList_lb.setText( '[ Motion List ]' )
        
        self.tab3_motion_list = QtGui.QListWidget(self.tab_3)
        self.tab3_motion_list.setSelectionMode(QtGui.QAbstractItemView.MultiSelection)
        self.tab3_motion_list.setGeometry(QtCore.QRect(210, 30, 191, 192))
                
        self.tab3_motionImport_btn  = QtGui.QPushButton(self.tab_3)
        self.tab3_motionImport_btn.setGeometry(QtCore.QRect(210, 230, 91, 31))
        self.tab3_motionImport_btn.setText( 'Import' )
        
        self.tab3_motionDelete_btn = QtGui.QPushButton(self.tab_3)
        self.tab3_motionDelete_btn.setGeometry(QtCore.QRect(314, 230, 91, 31))
        self.tab3_motionDelete_btn.setText( 'Delete' )
        
        self.tab_4 = QtGui.QWidget()
        self.tabWidget.addTab( self.tab_4 , 'Random Animation' )        
        
        self.tab4_strtRandRange_lb = QtGui.QLabel(self.tab_4)
        self.tab4_strtRandRange_lb.setGeometry(QtCore.QRect(20, 20, 200, 21))
        self.tab4_strtRandRange_lb.setText( 'Start Frame Random Range' )
        self.tab4_strtRandRange_lb.setFont( font )
       
        self.tab4_scattering_btn = QtGui.QPushButton(self.tab_4)
        self.tab4_scattering_btn.setGeometry(QtCore.QRect(20, 100, 180, 41))
        self.tab4_scattering_btn.setText( 'Scattering' )
        self.tab4_scattering_btn.setFont( font )
        self.tab4_scattering_btn.setEnabled( False )
        
        self.tab4_delScat_btn = QtGui.QPushButton(self.tab_4)
        self.tab4_delScat_btn.setGeometry(QtCore.QRect(210, 100, 180, 41))
        self.tab4_delScat_btn.setText( 'Delete scattered Objects' )
        self.tab4_delScat_btn.setFont( font )
        self.tab4_delScat_btn.setEnabled( False )
        
        self.tab4_radStrt_spin = QtGui.QSpinBox(self.tab_4)
        self.tab4_radStrt_spin.setGeometry(QtCore.QRect( 30, 50, 100 , 22))
        self.tab4_radStrt_spin.setMinimum( -100 )
        self.tab4_radStrt_spin.setValue( -20 )
        
        self.tab4_radEnd_spin = QtGui.QSpinBox(self.tab_4)
        self.tab4_radEnd_spin.setGeometry(QtCore.QRect( 220, 50, 100 , 22))
        self.tab4_radEnd_spin.setMinimum( -100 )
        self.tab4_radEnd_spin.setValue( -1 )
        
        self.tab4_animObj_btn = QtGui.QPushButton(self.tab_4)
        self.tab4_animObj_btn.setGeometry(QtCore.QRect(30, 170, 350, 41))
        self.tab4_animObj_btn.setText( 'Bake height animation' )
        self.tab4_animObj_btn.setFont( font )
        self.tab4_animObj_btn.setEnabled( False )
    
if __name__ == "__main__" :
    if MAYA :
        crowd_ui = crowd_ui()
        crowd_ui.setupUi()
        crowd_ui.show()
    else :
        app = QtGui.QApplication(sys.argv)
        crowd_ui = crowd_ui()
        crowd_ui.setupUi()
        crowd_ui.show()
        app.exec_()
        
        